package com.adv.activity;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.view.Menu;

@SuppressLint("InlinedApi")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class Fullscreen extends SherlockActivity {

	private WebView wv;
	private WebSettings setting;
	private ActionBar actionbar;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Hide something
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
			View decorView = getWindow().getDecorView();
			int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
			decorView.setSystemUiVisibility(uiOptions);
		}
		setContentView(R.layout.activity_fullscreen);

		actionbar = getSupportActionBar();
		actionbar.setDisplayHomeAsUpEnabled(true);
		actionbar.setSubtitle("Chi tiết");

		wv = (WebView) findViewById(R.id.wv);
		setting = wv.getSettings();
		setting.setAppCacheEnabled(true);
		setting.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);

		setting.setUseWideViewPort(true);
		setting.setLoadWithOverviewMode(true);
		setting.setSupportZoom(true);
		setting.setBuiltInZoomControls(true);
		wv.setKeepScreenOn(true);

		// TODO: get url
		Intent intent = getIntent();
		String link = intent.getStringExtra(Details.LINK_DETAIL);
		if (link != null)
			wv.loadUrl(link);
		else
			Log.e(getPackageName(), "Fullsc activity Link bundle is null");
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getSupportMenuInflater().inflate(R.menu.menu, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onMenuItemSelected(int featureId,
			com.actionbarsherlock.view.MenuItem item) {
		if (item.getItemId() == android.R.id.home) {
			finish();
		} else if (item.getItemId() == R.id.action_home) {
			startActivity(new Intent(Fullscreen.this, Catalog.class));
			finish();
		}
		return true;
	}

}
